<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    please input:<input type="text" id="str">
    <input type="button" id="calculate" onclick="cal()" value="calculate">
    <div id="result"></div>
    <script>
        function cal(){
            var str=document.getElementById('str').value;
            var f =new Function('return '+str+'');
            document.getElementById('result').innerHTML=f();
        }
        function f(){
            return s;
        }
    </script>
</body>
</html>